package com.aaa.controller;

import com.aaa.vo.R;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
@PostMapping("/login")
    public R login(String username, String userpwd){
    Subject subject = SecurityUtils.getSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(username, userpwd);
    System.out.println(token);
    try {
        subject.login(token);
       return new R(200,"登录成功",null);
    }catch (Exception e){
        return new R(401,"登录失败",null);
    }

}
    @PostMapping("/unlogin")
    public R unlogin(){
        return new R(403,"登录错误",null);
    }
}
